{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Microservice Tests\n",
    "\n",
    "Run:\n",
    "```\n",
    "docker run -it --rm -p 5000:5000 seldonio/identity_model_rest:0.1\n",
    "docker run -it --rm -p 5001:5001 -e PREDICTIVE_UNIT_SERVICE_PORT=5001 seldonio/identity_model_grpc:0.1\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from seldon_core.seldon_client import SeldonClient\n",
    "sc = SeldonClient()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success:True message:\n",
      "Request:\n",
      "data {\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.20275783666652192\n",
      "  }\n",
      "}\n",
      "\n",
      "Response:\n",
      "meta {\n",
      "}\n",
      "data {\n",
      "  names: \"t:0\"\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.20275783666652192\n",
      "  }\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"rest\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success:True message:\n",
      "Request:\n",
      "data {\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.14290652226750622\n",
      "  }\n",
      "}\n",
      "\n",
      "Response:\n",
      "meta {\n",
      "}\n",
      "data {\n",
      "  names: \"t:0\"\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.14290652226750622\n",
      "  }\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"grpc\",microservice_endpoint=\"localhost:5001\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success:True message:\n",
      "Request:\n",
      "seldonMessages {\n",
      "  data {\n",
      "    tensor {\n",
      "      shape: 1\n",
      "      shape: 1\n",
      "      values: 0.8539616115679378\n",
      "    }\n",
      "  }\n",
      "}\n",
      "seldonMessages {\n",
      "  data {\n",
      "    tensor {\n",
      "      shape: 1\n",
      "      shape: 1\n",
      "      values: 0.6725465119316986\n",
      "    }\n",
      "  }\n",
      "}\n",
      "\n",
      "Response:\n",
      "meta {\n",
      "}\n",
      "data {\n",
      "  names: \"t:0\"\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.8539616115679378\n",
      "  }\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "p = sc.microservice(method=\"aggregate\",transport=\"rest\",ndatas=2)\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Success:True message:\n",
      "Request:\n",
      "seldonMessages {\n",
      "  data {\n",
      "    tensor {\n",
      "      shape: 1\n",
      "      shape: 1\n",
      "      values: 0.5939194473220454\n",
      "    }\n",
      "  }\n",
      "}\n",
      "seldonMessages {\n",
      "  data {\n",
      "    tensor {\n",
      "      shape: 1\n",
      "      shape: 1\n",
      "      values: 0.32767806897749363\n",
      "    }\n",
      "  }\n",
      "}\n",
      "\n",
      "Response:\n",
      "meta {\n",
      "}\n",
      "data {\n",
      "  names: \"t:0\"\n",
      "  tensor {\n",
      "    shape: 1\n",
      "    shape: 1\n",
      "    values: 0.5939194473220454\n",
      "  }\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "p = sc.microservice(method=\"aggregate\",transport=\"grpc\",ndatas=2,microservice_endpoint=\"localhost:5001\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"rest\")\n",
    "print(p)\n",
    "f = sc.microservice_feedback(prediction_request=p.request,prediction_response=p.response,reward=1.0,transport=\"rest\")\n",
    "print(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"grpc\",microservice_endpoint=\"localhost:5001\")\n",
    "print(p)\n",
    "f = sc.microservice_feedback(prediction_request=p.request,prediction_response=p.response,reward=1.0,transport=\"grpc\",microservice_endpoint=\"localhost:5001\")\n",
    "print(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"rest\",bin_data=b\"123\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"rest\",str_data=\"123\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"aggregate\",transport=\"rest\",datas=[\"123\",\"456\"])\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"grpc\",microservice_endpoint=\"localhost:5001\",bin_data=b\"123\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"predict\",transport=\"grpc\",microservice_endpoint=\"localhost:5001\",str_data=\"123\")\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "p = sc.microservice(method=\"aggregate\",transport=\"grpc\",microservice_endpoint=\"localhost:5001\",datas=[\"123\",\"456\"])\n",
    "print(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import inspect\n",
    "\n",
    "class Myclass(object):\n",
    "    \n",
    "    def __init__(self,a=1,b=2):\n",
    "        self.a = a\n",
    "        self.b = b\n",
    "        \n",
    "    def f1(self,c=2,d=4):\n",
    "        print(vars(self))\n",
    "        print(vars())\n",
    " \n",
    "x = Myclass()\n",
    "x.f1()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
